package main

import (
	"fmt"
	"time"

	"github.com/gomodule/redigo/redis"
)

func main() {
	pool := &redis.Pool{
		//最大活跃连接数，0代表无限
		MaxActive: 888,
		//最大闲置连接数
		MaxIdle: 20,
		//闲置连接的超时时间
		IdleTimeout: time.Second * 100,
		//定义拨号获得连接的函数
		Dial: func() (redis.Conn, error) {
			return redis.Dial("tcp", "127.0.0.1:6379")
		},
	}
	defer pool.Close()

	conn := pool.Get()
	defer conn.Close()
	key := "conn"
	if _, err := conn.Do("set", key, 100, "EX", 3600); err != nil {
		panic(err)
	}
	if val, err := redis.String(conn.Do("Get", key)); err != nil {
		panic(err)
	} else {
		fmt.Println(val)
		conn.Do("del", key)
	}
}
